package com.link.ppt.Base;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.afollestad.materialdialogs.MaterialDialog;
import com.jaeger.library.StatusBarUtil;
import com.link.ppt.App.App;
import com.link.ppt.Utils.StatusBarFontUtils;

/**
 * Activity基础类库
 * Created by liukanshan on 2016/12/8.
 */

public abstract class BaseActivity extends AppCompatActivity {

    private MaterialDialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        StatusBarUtil.setColorNoTranslucent(this, Color.parseColor("#ffffff"));
        StatusBarFontUtils.setStatusBarDarkFont(this,true);
        initProgressDialog();
        setupView();
        setupData();
        App.GetInstance().addActivity(this);
    }

    private void initProgressDialog(){
        progressDialog = new MaterialDialog.Builder(this)
                .progress(true, 0)
                .content("请等待...")
                .autoDismiss(false)
                .cancelable(true)
                .build();
    }

    public void showProgress(){
        progressDialog.show();
    }

    public void hideProgress(){
        progressDialog.dismiss();
    }

    public abstract int getLayoutId();

    public abstract void setupView();

    public abstract void setupData();

    public <T extends View> T $(int id) {
        return (T) super.findViewById(id);
    }

    protected void hidenInput(View view) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}
